import math
import time
import sys

def sieve(n):
    if n < 3:
        return [False] * n
    is_prime = [True] * n
    is_prime[0] = is_prime[1] = False
    sqrt_n = math.isqrt(n)
    for i in range(2, sqrt_n + 1):
        if is_prime[i]:
            start = i * i
            step = i
            is_prime[start:n:step] = [False] * ((n - start - 1) // step + 1)
    return is_prime

if __name__ == "__main__":
    n = int(sys.argv[1]) if len(sys.argv) > 1 else 10_000_000
    runs = int(sys.argv[2]) if len(sys.argv) > 2 else 5
    print_flag = len(sys.argv) > 3  # 第三个参数存在则打印

    # 预热运行
    sieve(1_000_000)
    
    durations = []
    for _ in range(runs):
        start = time.perf_counter()
        primes = sieve(n)
        end = time.perf_counter()
        if print_flag:
            print(primes)
        durations.append((end - start) * 1000)
    
    avg_time = sum(durations) / runs
    print(f"Python | {avg_time:.2f} ms")